
func void B_RestartFreeze()
{
	if((Npc_GetLastHitSpellID(self) == SPL_IceCube) || (Npc_GetLastHitSpellID(self) == SPL_IceWave))
	{
		Npc_SetStateTime(self,0);
	};
};

func void B_StopMagicFreeze()
{
	if(Hlp_GetInstanceID(self) == Hlp_GetInstanceID(hero))
	{
		Perception_Set_Normal();
	};
	Npc_PercEnable(self,PERC_ASSESSMAGIC,B_AssessMagic);
	Npc_ClearAIQueue(self);
	AI_Standup(self);
	if(self.guild < GIL_SEPERATOR_HUM)
	{
		B_AssessDamage();
	}
	else
	{
		Npc_SetTempAttitude(self,ATT_HOSTILE);
	};
};

func int ZS_MagicFreeze()
{
	if(Hlp_GetInstanceID(self) == Hlp_GetInstanceID(hero))
	{
		if(DAMAGEFREEZE == TRUE)
		{
			Npc_PercEnable(self,PERC_ASSESSMAGIC,B_RestartFreeze);
			Npc_StopAni(self,"S_FIRE_VICTIM");
			if(!C_BodyStateContains(self,BS_UNCONSCIOUS))
			{
				AI_PlayAniBS(self,"T_STAND_2_FREEZE_VICTIM",BS_UNCONSCIOUS);
			};
			self.aivar[AIV_FreezeStateTime] = 0;
		};
	}
	else
	{
		Npc_PercEnable(self,PERC_ASSESSMAGIC,B_RestartFreeze);
		Npc_StopAni(self,"S_FIRE_VICTIM");
		if(self.guild > GIL_SEPERATOR_HUM)
		{
			if(!C_BodyStateContains(self,BS_STUMBLE))
			{
				AI_PlayAniBS(self,"T_STAND_2_FREEZE_VICTIM",BS_STUMBLE);
			};
		}
		else if(self.guild != GIL_DMT)
		{
			if(!C_BodyStateContains(self,BS_UNCONSCIOUS))
			{
				AI_PlayAniBS(self,"T_STAND_2_FREEZE_VICTIM",BS_UNCONSCIOUS);
			};
		}
		else if(!C_BodyStateContains(self,BS_STUMBLE))
		{
			AI_PlayAniBS(self,"T_STAND_2_FREEZE_VICTIM",BS_STUMBLE);
		};
		self.aivar[AIV_FreezeStateTime] = 0;
	};
	return TRUE;
};

func int ZS_MagicFreeze_Loop()
{
	if(Hlp_GetInstanceID(self) == Hlp_GetInstanceID(hero))
	{
		if(DAMAGEFREEZE == TRUE)
		{
			if(Npc_GetStateTime(self) != self.aivar[AIV_FreezeStateTime])
			{
				self.aivar[AIV_FreezeStateTime] = Npc_GetStateTime(self);
				if(self.attribute[ATR_HITPOINTS] > (self.attribute[ATR_HITPOINTS] - SPL_FREEZE_DAMAGE))
				{
					B_MagicHurtNpc(other,self,SPL_FREEZE_DAMAGE);
				};
			};
		};
		if(REGENERATEFREEZE == TRUE)
		{
			if(HEALRINGEQUIP == TRUE)
			{
				ZSCOUNTHEAL = ZSCOUNTHEAL + 1;
			};
			if(MANARINGEQUIP == TRUE)
			{
				ZSCOUNTMANA = ZSCOUNTMANA + 1;
			};
			if(ZSCOUNTMANA > 10)
			{
				ZSCOUNTMANA = 0;
				if((hero.attribute[ATR_MANA] < hero.attribute[ATR_MANA_MAX]) && (MANARINGEQUIP == TRUE))
				{
					PROCESSREGENERATEMANAEND = FALSE;
					hero.attribute[ATR_MANA] = hero.attribute[ATR_MANA] + 1;
					if((hero.attribute[ATR_MANA] < hero.attribute[ATR_MANA_MAX]) && (hero.guild == GIL_NOV))
					{
						hero.attribute[ATR_MANA] = hero.attribute[ATR_MANA] + 1;
					};
					if((hero.attribute[ATR_MANA] < hero.attribute[ATR_MANA_MAX]) && ((hero.guild == GIL_KDF) || (hero.guild == GIL_KDW)))
					{
						MANALEVEL = (hero.level * 100) / 1000;
						hero.attribute[ATR_MANA] = hero.attribute[ATR_MANA] + MANALEVEL;
					};
					Wld_PlayEffect("spellFX_LIGHTSTAR_BLUE",hero,hero,0,0,0,FALSE);
					if((PROCESSREGENERATE == FALSE) && (DAMAGEFREEZE == FALSE))
					{
						AI_PlayAni(self,"T_MAGRUN_2_HEASHOOT");
						PROCESSREGENERATE = TRUE;
					};
				};
				if(hero.attribute[ATR_MANA] > hero.attribute[ATR_MANA_MAX])
				{
					hero.attribute[ATR_MANA] = hero.attribute[ATR_MANA_MAX];
				};
				if((hero.attribute[ATR_MANA] == hero.attribute[ATR_MANA_MAX]) && (MANARINGEQUIP == TRUE))
				{
					PROCESSREGENERATEMANAEND = TRUE;
				};
			};
			if(ZSCOUNTHEAL > 10)
			{
				ZSCOUNTHEAL = 0;
				if((hero.attribute[ATR_HITPOINTS] < hero.attribute[ATR_HITPOINTS_MAX]) && (HEALRINGEQUIP == TRUE))
				{
					PROCESSREGENERATEHPEND = FALSE;
					hero.attribute[ATR_HITPOINTS] = hero.attribute[ATR_HITPOINTS] + 5;
					if((hero.attribute[ATR_HITPOINTS] < hero.attribute[ATR_HITPOINTS_MAX]) && (hero.guild == GIL_PAL))
					{
						HEALLEVEL = ((hero.level * 100) / 1000) * 2;
						hero.attribute[ATR_HITPOINTS] = hero.attribute[ATR_HITPOINTS] + HEALLEVEL;
					};
					Wld_PlayEffect("spellFX_LIGHTSTAR_RED",hero,hero,0,0,0,FALSE);
					if((PROCESSREGENERATE == FALSE) && (DAMAGEFREEZE == FALSE))
					{
						AI_PlayAni(self,"T_MAGRUN_2_HEASHOOT");
						PROCESSREGENERATE = TRUE;
					};
				};
				if(hero.attribute[ATR_HITPOINTS] > hero.attribute[ATR_HITPOINTS_MAX])
				{
					hero.attribute[ATR_HITPOINTS] = hero.attribute[ATR_HITPOINTS_MAX];
				};
				if((hero.attribute[ATR_HITPOINTS] == hero.attribute[ATR_HITPOINTS_MAX]) && (HEALRINGEQUIP == TRUE))
				{
					PROCESSREGENERATEHPEND = TRUE;
				};
			};
			if((PROCESSREGENERATEMANAEND == TRUE) || (PROCESSREGENERATEHPEND == TRUE))
			{
				if((PROCESSREGENERATEMANAEND == TRUE) && (PROCESSREGENERATEHPEND == TRUE))
				{
					MANARINGEQUIP = FALSE;
					HEALRINGEQUIP = FALSE;
					PROCESSREGENERATE = FALSE;
					PROCESSREGENERATEMANAEND = FALSE;
					PROCESSREGENERATEHPEND = FALSE;
					REGENERATEFREEZE = FALSE;
					Npc_RemoveInvItems(hero,itri_regeneratemana,1);
					Npc_RemoveInvItems(hero,itri_regeneratehp,1);
					CreateInvItems(hero,itri_regeneratemana,1);
					CreateInvItems(hero,itri_regeneratehp,1);
					Npc_StopAni(self,"T_MAGRUN_2_HEASHOOT");
					Npc_ClearAIQueue(self);
					AI_Standup(self);
				}
				else if((PROCESSREGENERATEMANAEND == TRUE) && (PROCESSREGENERATEHPEND == FALSE))
				{
					if(HEALRINGEQUIP == FALSE)
					{
						MANARINGEQUIP = FALSE;
						PROCESSREGENERATE = FALSE;
						PROCESSREGENERATEMANAEND = FALSE;
						REGENERATEFREEZE = FALSE;
						Npc_RemoveInvItems(hero,itri_regeneratemana,1);
						CreateInvItems(hero,itri_regeneratemana,1);
						Npc_StopAni(self,"T_MAGRUN_2_HEASHOOT");
						Npc_ClearAIQueue(self);
						AI_Standup(self);
					};
				}
				else if((PROCESSREGENERATEMANAEND == FALSE) && (PROCESSREGENERATEHPEND == TRUE))
				{
					if(MANARINGEQUIP == FALSE)
					{
						HEALRINGEQUIP = FALSE;
						PROCESSREGENERATE = FALSE;
						PROCESSREGENERATEHPEND = FALSE;
						REGENERATEFREEZE = FALSE;
						Npc_RemoveInvItems(hero,itri_regeneratehp,1);
						CreateInvItems(hero,itri_regeneratehp,1);
						Npc_StopAni(self,"T_MAGRUN_2_HEASHOOT");
						Npc_ClearAIQueue(self);
						AI_Standup(self);
					};
				};
			};
		};
		if((MANARINGEQUIP == FALSE) && (HEALRINGEQUIP == FALSE) && (REGENERATEFREEZE == FALSE))
		{
			if(DAMAGEFREEZE == TRUE)
			{
				if(Npc_GetStateTime(self) > SPL_TIME_FREEZE)
				{
					DAMAGEFREEZE = FALSE;
					B_StopMagicFreeze();
					return LOOP_END;
				}
				else
				{
					return LOOP_CONTINUE;
				};
			}
			else
			{
				return LOOP_END;
			};
		};
		return LOOP_CONTINUE;
	}
	else
	{
		if(Npc_GetStateTime(self) > SPL_TIME_FREEZE)
		{
			B_StopMagicFreeze();
			return LOOP_END;
		};
		if(Npc_GetStateTime(self) != self.aivar[AIV_FreezeStateTime])
		{
			self.aivar[AIV_FreezeStateTime] = Npc_GetStateTime(self);
			if(self.attribute[ATR_HITPOINTS] > (self.attribute[ATR_HITPOINTS] - SPL_FREEZE_DAMAGE))
			{
				if((self.guild == GIL_FIREGOLEM) || (self.aivar[AIV_MM_REAL_ID] == ID_FIREWARAN) || (self.aivar[AIV_MM_REAL_ID] == ID_DRAGON_FIRE))
				{
					B_MagicHurtNpc(other,self,SPL_FREEZE_DAMAGE * 2);
					return LOOP_CONTINUE;
				};
				if((self.guild == GIL_ICEGOLEM) || (self.aivar[AIV_MM_REAL_ID] == ID_DRAGON_ICE))
				{
					B_MagicHurtNpc(other,self,SPL_FREEZE_DAMAGE / 2);
					return LOOP_CONTINUE;
				};
				B_MagicHurtNpc(other,self,SPL_FREEZE_DAMAGE);
			};
		};
		return LOOP_CONTINUE;
	};
};

func void ZS_MagicFreeze_End()
{
};

